package com.ubisolv.usedragviewset;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PointF;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.ubisolv.util.u;
import com.ubisolv.view.DragViewMatrixUtil.ScaleMethod;
import com.ubisolv.view.DragViewSet;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		final DragViewSet viewSet = (DragViewSet)findViewById(R.id.drg_sample);
		Bitmap rear = BitmapFactory.decodeResource(this.getResources(), R.drawable.system_architecture);
		
		u.d("MainActivity.onCreate", "view-size:[%d]-[%d], bitmap-size:[%d]-[%d]", viewSet.getWidth(), viewSet.getHeight(), rear.getWidth(), rear.getHeight());
		
		viewSet.setRearBitmap(rear, true, ScaleMethod.SCALE_FIT_MAX);
		//viewSet.setRearBitmap(rear, true, ScaleMethod.SCALE_FIT_MIN);
		
		Bitmap eyeLeft = BitmapFactory.decodeResource(getResources(), R.drawable.eye);
		Bitmap eyeRight = BitmapFactory.decodeResource(getResources(), R.drawable.eye);
		Bitmap mouse = BitmapFactory.decodeResource(getResources(), R.drawable.mouth);
		
		viewSet.setFrontBitmap(
				new Bitmap[] {eyeLeft, eyeRight, mouse}, 
				//new PointF[] {new PointF(331, 81), new PointF(752, 81), new PointF(537, 529)});
				new PointF[] {new PointF(131, 81), new PointF(852, 81), new PointF(537, 929)});
		
		Button button = (Button)findViewById(R.id.btn_ok);
		button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				PointF point = null;
				
				for (int i = 0; i < 3; i++) {
					point = viewSet.getFrontPosition(i);
					u.d("MainActivity.button.onClick", "front [%d] imagee point:[%.2f]-[%.2f]", i, point.x, point.y);
				}
			}
		});
	}

}
